﻿@using BBCore.Core.Models.Samples
@using BBCore.Application.Interface
@using BBCore.Server.PublicComponentBase
@using BBCore.Core.Models.EnumTypes
@using Blazored.FluentValidation;
@using System.Diagnostics.CodeAnalysis;
@implements IResultDialog;
@inject DialogService DialogService
@inject IJSRuntime JSRuntime
@inject IClosedxmlExcelExportService ClosedxmlExcelExportService
@inherits Master_Detail_ComponentBase
<ValidateForm Model="Model" OnValidSubmit="OnValidSubmit">
    <p style="color: red;">
        <FluentValidationValidator />
        <ValidationSummary />
    </p>
    <Row ItemsPerRow="ItemsPerRow.Six" RowType="RowType.Inline">
        <BootstrapInput @bind-Value="Model.JOB_NO" ShowLabel="true" />
        <p style="color: red;"><ValidationMessage For="()=>Model.JOB_NO" /></p>
        <BootstrapInput @bind-Value="Model.LINE_CODE" ShowLabel="true" />
        <BootstrapInput @bind-Value="Model.QUANTITY" ShowLabel="true" />
        <BootstrapInput @bind-Value="Model.REQ_DATE" ShowLabel="true" />
    </Row>
    <hr />
    <div style="height:650px;overflow:auto;">
        @* IsExcel="true" *@
        <Table TItem="HYJ_Detail_Table" ShowDefaultButtons="true" ShowExtendButtons="true" ShowExtendEditButton="false" ShowExtendDeleteButton="false"
               ShowLineNo="true" IsFixedHeader="true" FixedExtendButtonsColumn="true" IsBordered="true" IsMultipleSelect="true" 
               ShowAddButton="false" ShowEditButton="false" ShowDeleteButton="true" OnDeleteAsync="OnBatchDeleteAsync" DeleteButtonText="批量删除"
               ShowToastAfterSaveOrDeleteModel="false"
               ShowToolbar="true" Items="FilteredDetails" ShowRefresh="false">
            <TableColumns>
                <TableColumn @bind-Field="@context.ITEM">
                    <Template Context="v">
                        <BootstrapInput @bind-Value="v.Row.ITEM" @ref="_newInputRef" Color="Color.Info" @onfocusout="e=>((HYJ_Detail_Table)v.Row).ITEM=v.Row.ITEM" />
                    </Template>
                </TableColumn>
                <TableColumn @bind-Field="@context.LEVEL2">
                    <Template Context="v">
                        <BootstrapInput @bind-Value="v.Row.LEVEL2" Color="Color.Info" @onfocusout="e=>((HYJ_Detail_Table)v.Row).LEVEL2=v.Row.LEVEL2" />
                    </Template>
                </TableColumn>
            </TableColumns>
            <TableToolbarTemplate>
                <div class="btn-group" role="group">
                    <Button Text="添加明细" TItem="HYJ_Detail_Table" IsDisabled="@(!string.IsNullOrEmpty(searchQuery))" OnClick="AddNewRow" />
                </div>
            </TableToolbarTemplate>
            <TableExtensionToolbarBeforeTemplate>
                <div class="input-group">
                    <span class="input-group-text">搜索:</span>
                    <input type="text" class="form-control" @bind-value="searchQuery" @bind-value:event="oninput" placeholder="按 ITEM 或 LEVEL2 搜索" />
                    <button class="btn btn-secondary" type="button" @onclick="ClearSearchQuery">清空</button>
                    <button class="btn btn-primary" type="button" @onclick="ExportByTemplate">导出此页(模板导出)</button>
                </div>
            </TableExtensionToolbarBeforeTemplate>
            <RowButtonTemplate>
                <TableCellButton Color="Color.Danger" Text="删除" OnClick="()=>Model.Details?.Remove(context)" />
            </RowButtonTemplate>
        </Table>
    </div>
    <div style="text-align:center;padding:10px;">
        <PopConfirmButton Placement="Placement.Top" Color="Color.Primary" ConfirmIcon="fa fa-exclamation-triangle text-info"
                          ConfirmButtonColor="Color.Success" Text="提交表单" Content="确定提交数据吗？" Icon="fa fa-save fa-fw"
                          ButtonType="ButtonType.Submit" IsAsync="true" />
        <Button Text="重置" TItem="HYJ_Detail_Table" OnClick="ShowConfirmation" />       
    </div>
</ValidateForm>
